package com.ruoyi.system.service.impl;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.system.domain.SysUserbean;
import com.ruoyi.system.domain.ZtfAppCodeNc;
import com.ruoyi.system.domain.ZtfSysUserbean;
import com.ruoyi.system.mapper.SysUserbeanMapper;
import com.ruoyi.system.mapper.ZtfAppCodeNcMapper;
import com.ruoyi.system.mapper.ZtfSysUserbeanMapper;
import com.ruoyi.system.service.IZtfAppCodeNcService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class IZtfAppCodeNcServiceImpl implements IZtfAppCodeNcService {
    @Autowired
    private ZtfAppCodeNcMapper ztfAppCodeNcMapper;

    @Autowired
    private SysUserbeanMapper sysUserbeanMapper;
    /**
     * 激活码激活
     * @param xphone
     * @param codeName
     * @param userId
     * @return
     */
    @Override
    public int editCode( String xphone,  String codeName,  Long userId) {
        //根据激活码查询激活码数据
        ZtfAppCodeNc ztfAppCodeNc= ztfAppCodeNcMapper.selectCodeBycodeName(codeName);
        //根据用户查询手机号
        SysUserbean sysUserbean=sysUserbeanMapper.selectSysUserbeanByUserId(userId);

        if(ztfAppCodeNc==null){
            throw new ServiceException("您输入的激活码不存在",409);
        }

        if(!xphone.equals(sysUserbean.getPhonenumber())){
            throw new ServiceException("请输入正确的手机号",408);
        }

//        if(ztfAppCodeNc.getStatus()==1){
//            throw new ServiceException("该激活码已经激活无需在激活",407);
//        }
        //获取激活码
//       String codeName1=ztfAppCodeNc.getCodeName();
//       if(!codeName1.equals(codeName)) {
//           throw new ServiceException("您输入的激活码不存在");
//       }
        return ztfAppCodeNcMapper.updateCodeStatus(xphone,codeName,userId);
    }
}
